from django.db import models
from user.models import Address

# 店铺
class Work(models.Model):
    name = models.CharField(max_length=64, verbose_name='店铺名称')
    logo = models.CharField(max_length=256, verbose_name='logo地址')
    money = models.IntegerField(verbose_name='起送费')
    info = models.CharField(max_length=64, verbose_name='描述')
    address_detailed = models.CharField(max_length=128, verbose_name="店铺具体位置")
    longitude = models.DecimalField(max_digits=10, decimal_places=6, verbose_name="经度")
    latitude = models.DecimalField(max_digits=10, decimal_places=6, verbose_name="维度")

    class Meta:
        db_table = 'work'


# 商品分类
class GoodCate(models.Model):
    catename = models.CharField(max_length=64, verbose_name='分类名称')
    create_time = models.DateTimeField("创建时间", auto_now_add=True,editable=True, null=True)
    update_time = models.DateTimeField("更新时间", auto_now=True,editable=True, null=True)
    catetype = models.BooleanField(default=False, verbose_name='分类类型:0,菜品分类,1,套餐分类')
    # 外键关系
    work_id = models.ForeignKey(Work,on_delete=models.CASCADE,verbose_name='所属店铺')

    class Meta:
        db_table = 'good_cate'




# 菜品表
class Good(models.Model):
    good_name = models.CharField(max_length=64, verbose_name='菜品/套餐名字')
    price = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='单价')
    logo = models.CharField(max_length=256, verbose_name='logo')
    info = models.CharField(max_length=64, verbose_name='简介')
    # cate_id = models.IntegerField(verbose_name='分类id')
    # work_id = models.IntegerField(verbose_name='店铺id')
    # cate = models.CharField(max_length=64, verbose_name='菜品分类', default='')
    create_time = models.DateTimeField("创建时间", auto_now_add=True, editable=True, null=True)
    update_time = models.DateTimeField("更新时间", auto_now=True, editable=True, null=True)
    is_show = models.IntegerField('是否在售0:False,1:True', default=1,choices=((0,'不售卖'),(1,'售卖')))
    # 外键关系
    cate_id = models.ForeignKey(GoodCate,on_delete=models.CASCADE,verbose_name='商品分类')
    work = models.ForeignKey(Work,on_delete=models.CASCADE,verbose_name='店铺')

    class Meta:
        db_table = 'good'


# 套餐菜品关系表
class TaoGood(models.Model):
    price = models.DecimalField(max_digits=5, decimal_places=2, verbose_name='商品价格')
    # cate = models.CharField(max_length=64, verbose_name='菜品分类')
    create_time = models.DateTimeField("创建时间", auto_now_add=True, editable=True, null=True)
    update_time = models.DateTimeField("更新时间", auto_now=True, editable=True, null=True)
    # 外键关系
    good = models.ForeignKey(Good,on_delete=models.CASCADE,verbose_name='菜品名')

    class Meta:
        db_table = 'tao_good'



